package com.lb.controller;

import com.lb.entity.TbMovieType;
import com.lb.service.TbMovieTypeService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (TbMovieType)表控制层
 *
 * @author libo
 * @since 2024-09-09 14:09:15
 */
@RestController
@RequestMapping("tbMovieType")
public class TbMovieTypeController {
    /**
     * 服务对象
     */
    @Resource
    private TbMovieTypeService tbMovieTypeService;

    /**
     * 分页查询
     *
     * @param tbMovieType 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<TbMovieType>> queryByPage(TbMovieType tbMovieType, PageRequest pageRequest) {
        return ResponseEntity.ok(this.tbMovieTypeService.queryByPage(tbMovieType, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<TbMovieType> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.tbMovieTypeService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param tbMovieType 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<TbMovieType> add(TbMovieType tbMovieType) {
        return ResponseEntity.ok(this.tbMovieTypeService.insert(tbMovieType));
    }

    /**
     * 编辑数据
     *
     * @param tbMovieType 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<TbMovieType> edit(TbMovieType tbMovieType) {
        return ResponseEntity.ok(this.tbMovieTypeService.update(tbMovieType));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.tbMovieTypeService.deleteById(id));
    }

}

